package com.easyaop.test.core.intercept;

import com.easyaop.test.core.pointcut.MethodPointcut;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

public class VirtualMethodAdvice {
    @Advice.OnMethodEnter(//skipOn = Advice.OnNonDefaultValue.class
    )
    public static void methodEnter(@Advice.Origin("#t\\##m#d") String sig,
                                   //@Advice.This(optional = false) Object target,
                                   @Advice.Local("pointcut") MethodPointcut pointcut,
                                   @Advice.AllArguments Object... args) throws Throwable {
        /*pointcut = MethodPointcut.findMethodPointcut(sig);
        System.out.println(pointcut);*/
        //System.out.println(target);
        System.out.println("start..." + sig);
    }

    @Advice.OnMethodExit(onThrowable = Throwable.class
    )
    public static void methodExit(
            //@Advice.Local("pointcut") MethodPointcut methodPointcut,
            @Advice.Return(typing = Assigner.Typing.DYNAMIC, readOnly = false) Object returnValue,
            @Advice.Thrown(typing = Assigner.Typing.DYNAMIC) Throwable ex) {
        // System.out.println(methodPointcut);
        //System.out.println("end... result: " + returnValue);
        System.out.println("end...");
    }

    public interface Call {
        Object invoke(Object... args);
    }
}
